﻿using System.Diagnostics;
using System.IO;
using mmCore.Classes;
using mmCore.Interfaces;

namespace mmJdownloaderExtension
{
    public class JdownloaderExtension: IEpisodeExtension
    {
        private const string _mDefaulrJdownloaderLocation = @"C:\Program Files (x86)\JDownloader\JDownloader.exe";
        #region Implementation of IEpisodeExtension

        private static void ExecuteProcess(string str)
        {
            var proc = new Process
            {
                StartInfo =
                {
                    FileName = str,
                    UseShellExecute = true
                }
            };
            proc.Start();
        }

        public void Execute(Movie movie, Episode ep, object arg)
        {
            var location = arg as string;
            if(string.IsNullOrEmpty(location) || !File.Exists(location))
            {
                return;
            }
            ExecuteProcess(location);
        }

        public void Execute(Movie movie, Episode ep)
        {
            Execute(movie, ep, _mDefaulrJdownloaderLocation);
        }

        public string Title
        {
            get { return "Open JDownloader now!"; }
        }

        #endregion
    }
}
